package com.uu.distribution.jdk8;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * function demo
 */
public class FunctionTest {

    public static int compute(int a, Function<Integer, Integer> function) {
        return function.apply(a);
    }

    public static int composeCompute(int a, Function<Integer, Integer> function1, Function<Integer, Integer> function2) {
        return function1.compose(function2).apply(a);
    }

    public static int andThenCompute(int a,Function<Integer,Integer> function1,Function<Integer,Integer> function2){
        return function1.andThen(function2).apply(a);
    }

    public static int biCompute(int a,int b, BiFunction<Integer,Integer,Integer> function){
        return function.apply(a,b);
    }

    public static void main(String[] args) {
        // int result = compute(1, value -> value + 1);
        // int result = composeCompute(1,value -> value + 1,value -> value * 2);
        // int result = andThenCompute(1,value -> value + 1,value -> value * 2);
        int result = biCompute(1,2, Integer::sum);
        System.out.println("------->  " + result);

    }


}
